<?php 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields');

$option = JRequest::getCmd('option');
$items = JRequest::getVar('items');
$status = JFormHelper::loadFieldType('status', false);
$statusOptions = $status->getOptions();


JHtml::_('behavior.tooltip');
JHTML::_('behavior.modal');

?>

<script type="text/javascript">
	
	window.addEvent('domready', function(){
		$('#select_field').val(-1);
		$('#apply_btn').hide();
		$('#to_lb').hide();
		$('#status_field').hide();
		$('#text_input').hide();
		
		$('#select_field').change(function(){
			$('#text_input').val('');
			var idx = $('#select_field').val();
			
			if (idx == -1)
			{
				$('#apply_btn').hide();
				$('#to_lb').hide();
				$('#status_field').hide();
				$('#text_input').hide();
			}
			else
			{
				$('#apply_btn').show();
				$('#to_lb').show();
				
				if (idx == 0)
				{
					$('#status_field').show();
					$('#text_input').hide();
				}
				else if (idx == 1 || idx == 2)
				{
					$('#text_input').show();
					$('#status_field').hide();
				}
			}
		});
		
		$('#text_input').keydown(function(e){
			if ($('#select_field').val() == 2)
			{
				// Allow numeric only
				handleDigit(e);
			}
		});
	});
</script>
<form
	action="<?php echo JRoute::_('index.php?option='. $option .'&task=updatemany'); ?>"
	method="post" name="adminForm" id="order">
	<input type="hidden" name="option" value="<?php echo $option; ?>" /> <input
		type="hidden" name="task" value="order.updatemany" />
	<?php echo JHtml::_('form.token'); ?>

	<fieldset id='filter-bar'>
		<label for='select_field'>Update </label> <select id='select_field'
			name='select_field'>
			<option value='-1'>- Select -</option>
			<option value='0'>Status</option>
			<option value='1'>US Order Id</option>
			<option value='2'>Ship US</option>
		</select> <label id='to_lb'>To </label> <select id='status_field'
			name='status_field'>
			<?php echo JHtml::_('select.options', $statusOptions, 'value', 'text', null, true);?>
		</select> <input type='textbox' id='text_input' name='text_input' />
		<button id='apply_btn' type='button' onclick='this.form.submit();'>
			<?php echo JText::_('Apply'); ?>
		</button>
	</fieldset>

	<div id='editcell'>
		<table class='adminlist'>
			<thead>
				<tr>
					<th width='1%'><input style="visibility: hidden;" type='checkbox'
						onclick='Joomla.checkAll(this)'
						title='<?php echo JText::_('Check all')?>' />
					</th>
					<th><?php echo JText::_('COM_SHIPNHANH_ID_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_STATUS_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_ORDERDATE_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_CUSTOMER_LABEL');?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_USORDERID_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_PRODUCTNAME_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_WEB_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_PHOTO_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_COLOR_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_SIZE_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_WEBPRICE_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_TAX_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_SHIPUS_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_WEBCHARGE_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_SURCHARGE_LABEL'); ?></th>
					<th><?php echo JText::_('COM_SHIPNHANH_NOTE_LABEL'); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php
				if (!empty($items))
				{
					$k = 0;
					$i = 0;
					foreach ($items as $row)
					{
						$link = JRoute::_('index.php?option=' . $option . '&task=order.edit&id=' . $row->id);
						?>
				<tr class="row<?=$k?>">
					<td><input type='checkbox' name='cid[]' id='cb<?php echo $i++; ?>'
						value='<?php echo $row->id; ?>' checked="checked"
						style="visibility: hidden;" /></td>
					<td><a href='<?php echo $link; ?>'><?php echo $row->id; ?> </a></td>
					<td><?php echo $row->status; ?></td>
					<td><?php echo $row->orderdate; ?></td>
					<td><a class="modal" href='#<?php echo $row->username.$i; ?>'
						rel="{handler: 'clone'}"><?php echo $row->customer; ?> </a>
						<div style="display: none;">
							<div id="<?php echo $row->username.$i?>">
								<p>
									Phone: <a><?php echo $row->phone; ?> </a>
								</p>
								<p>
									Address: <a><?php echo $row->address; ?> </a>
								</p>
								<p>
									Email: <a><?php echo $row->email; ?> </a>
								</p>
							</div>
						</div>
					</td>
					<td><?php echo $row->usorderid; ?></td>
					<td><?php echo $row->productname; ?></td>
					<td><a href="<?php echo $row->link ?>"><?php echo $row->webname; ?>
					</a></td>
					<td><img src="<?php echo $row->photo; ?>"
						style="width: 100px; height: auto;" /></td>
					<td><?php echo $row->color; ?></td>
					<td><?php echo $row->size; ?></td>
					<td><?php echo $row->usprice; ?></td>
					<td><?php echo $row->tax; ?></td>
					<td><?php echo $row->shipus; ?></td>
					<td><?php echo $row->webcharge; ?></td>
					<td><?php echo $row->surcharge; ?></td>
					<td><?php echo $row->note; ?></td>
				</tr>
				<?php
			$k = 1 - $k;
			}
			}
			?>
			</tbody>
		</table>
	</div>
</form>
